package my_triangle;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Perro_Triangle {

	public static double side1, side2, side3;
	
	public static void main(String[] args){
		String userTriangleType;
		boolean isRight;
		getInput();
		try
		{
			if (side1 > 1000000 || side2 > 1000000 || side3 > 1000000)
				throw new SideTooBigException();
		}
		catch (SideTooBigException e)
		{
			System.out.println("ERROR! - One (or more) side(s) is greater than 1 million");
			System.exit(0);
		}
		try
		{
			if(isNegative(side1, side2, side3))
			{
				throw new SideNegativeException();
			}
		}
		catch (SideNegativeException e)
		{
			System.out.println("ERROR! - Triangles cannot have negative sides");
			System.exit(0);
		}
			
		try
		{
			if(!isTriangle(side1, side2, side3))
			{
				throw new NotTriangleException();
			}
		}
		catch(NotTriangleException e)
		{
			System.out.println("ERROR! - The sides given do not form a triangle");
			System.exit(0);
		}
		
		SimpleTriangle userTriangle = new SimpleTriangle(side1,side2,side3);
		userTriangleType = userTriangle.triangleType();
		isRight = userTriangle.rightTriangle();
		System.out.println("Your triangle with sides " + side1 +
				", " + side2 + ", " + side3 + " is a...");
		if(isRight)
		{
			System.out.println("Right " + userTriangleType + " Triangle");
		}
		else
		{
			System.out.println(userTriangleType + " Triangle");
		}
	}
	
	public static void getInput()
	{
		Scanner scan = new Scanner(System.in);
		System.out.println("This program takes three sides of a triangle");
		System.out.println("and reports if it is scalene, isosceles or");
		System.out.println("equilateral and whether or not it is");
		System.out.println("a right triangle.");
		try
		{
			System.out.print("Please enter a side length (Followed by enter):");
			side1 = scan.nextDouble();
			System.out.print("Please enter a side length (Followed by enter):");
		    side2 = scan.nextDouble();
			System.out.print("Please enter a side length (Followed by enter):");
			side3 = scan.nextDouble();
		}
		catch (InputMismatchException a)
		{
			System.out.println("ERROR! - Please enter only numerical inputs");
			System.exit(0);
		}
	}
	
	public static boolean isNegative(double a, double b, double c)
	{
		if( a < 0 || b < 0 || c < 0)
			return true;
		else
			return false;
	}
	
	public static boolean isTriangle(double a, double b, double c)
	{
		if(a + b <= c)
			return false;
		else if(a + c <= b)
			return false;
		else if(b + c <= a)
			return false;
		else
			return true;
	}
	
	public static boolean isZero(double a, double b, double c)
	{
		if (a == 0 || b == 0 || c == 0)
			return true;
		else
			return false;
	}

}
